﻿using FineUIPro;
using KPI_SYSTEM.Code;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace KPI_SYSTEM.KPIPage
{
    public partial class KPITemplate : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadBaseData();
                BindData();
            }
            PublicMethod.GetApprovalButton("KPITemplate.aspx", Toolbar2, Grid1);
        }

        /// <summary>
        /// 加载页面必备数据
        /// </summary>
        private void LoadBaseData()
        {
            DataTable tableCycle = SqlHelper.ExecuteDataset(CommandType.Text, @"SELECT REC_ID,DICT_NAME FROM SYSTEM_DICT WHERE PARENT_ID = (SELECT TOP 1 
                                                                                   REC_ID FROM SYSTEM_DICT WHERE PARENT_ID=0 AND DICT_NAME ='绩效考核周期')").Tables[0];
            ddlFormTEMPLATE_CYCLE.DataTextField = "DICT_NAME";
            ddlFormTEMPLATE_CYCLE.DataValueField = "REC_ID";
            ddlFormTEMPLATE_CYCLE.DataSource = tableCycle;
            ddlFormTEMPLATE_CYCLE.DataBind();


            DataTable tableType = SqlHelper.ExecuteDataset(CommandType.Text, @"SELECT REC_ID,DICT_NAME FROM SYSTEM_DICT WHERE PARENT_ID = (SELECT TOP 1 
                                                                                   REC_ID FROM SYSTEM_DICT WHERE PARENT_ID=0 AND DICT_NAME ='绩效考核方式')").Tables[0];
            ddlFormTEMPLATE_TYPE.DataTextField = "DICT_NAME";
            ddlFormTEMPLATE_TYPE.DataValueField = "REC_ID";
            ddlFormTEMPLATE_TYPE.DataSource = tableType;
            ddlFormTEMPLATE_TYPE.DataBind();

            DataTable tableCliniDept = SqlHelper.ExecuteDataset(CommandType.Text, @"SELECT REC_ID,DEPT_NAME FROM DEPT_DICT WHERE DEPT_STATUS=1 AND 
                                                                                    DEPT_TYPE=(SELECT TOP 1 REC_ID FROM SYSTEM_DICT WHERE DICT_NAME LIKE '%临床%' AND PARENT_ID=1)").Tables[0];
            chlFormCLINI_LIST.DataTextField = "DEPT_NAME";
            chlFormCLINI_LIST.DataValueField = "REC_ID";
            chlFormCLINI_LIST.DataSource = tableCliniDept;
            chlFormCLINI_LIST.DataBind();

            DataTable tableExecutiveDept = SqlHelper.ExecuteDataset(CommandType.Text, @"SELECT REC_ID,DEPT_NAME FROM DEPT_DICT WHERE DEPT_STATUS=1 AND 
                                                                                    DEPT_TYPE=(SELECT TOP 1 REC_ID FROM SYSTEM_DICT WHERE DICT_NAME LIKE '%行政%' AND PARENT_ID=1)").Tables[0];
            chlFormEXECUTIVE_LIST.DataTextField = "DEPT_NAME";
            chlFormEXECUTIVE_LIST.DataValueField = "REC_ID";
            chlFormEXECUTIVE_LIST.DataSource = tableExecutiveDept;
            chlFormEXECUTIVE_LIST.DataBind();

            DataTable tableMedicalDept = SqlHelper.ExecuteDataset(CommandType.Text, @"SELECT REC_ID,DEPT_NAME FROM DEPT_DICT WHERE DEPT_STATUS=1 AND 
                                                                                    DEPT_TYPE=(SELECT TOP 1 REC_ID FROM SYSTEM_DICT WHERE DICT_NAME LIKE '%医技%' AND PARENT_ID=1)").Tables[0];
            chlFormMEDICALSKILLS_LIST.DataTextField = "DEPT_NAME";
            chlFormMEDICALSKILLS_LIST.DataValueField = "REC_ID";
            chlFormMEDICALSKILLS_LIST.DataSource = tableMedicalDept;
            chlFormMEDICALSKILLS_LIST.DataBind();




            DataTable tableValueItemt = SqlHelper.ExecuteDataset(CommandType.Text, @"SELECT REC_ID,DICT_NAME FROM SYSTEM_DICT WHERE PARENT_ID=(SELECT REC_ID FROM SYSTEM_DICT WHERE DICT_NAME='医院数值类')").Tables[0];
            chlFormVALUE_ITEM.DataTextField = "DICT_NAME";
            chlFormVALUE_ITEM.DataValueField = "REC_ID";
            chlFormVALUE_ITEM.DataSource = tableValueItemt;
            chlFormVALUE_ITEM.DataBind();

            DataTable tableEfficiencyItem = SqlHelper.ExecuteDataset(CommandType.Text, @"SELECT * FROM VIEW_KPI_SCORE_ITEM WHERE ITE_TYPE_NAME LIKE '%效率%'").Tables[0];
            chlFormEfficiency.DataTextField = "ITEM_NAME";
            chlFormEfficiency.DataValueField = "REC_ID";
            chlFormEfficiency.DataSource = tableEfficiencyItem;
            chlFormEfficiency.DataBind();

            DataTable tableQualityItem = SqlHelper.ExecuteDataset(CommandType.Text, @"SELECT * FROM VIEW_KPI_SCORE_ITEM WHERE ITE_TYPE_NAME LIKE '%质量%'").Tables[0];
            chlFormQuality.DataTextField = "ITEM_NAME";
            chlFormQuality.DataValueField = "REC_ID";
            chlFormQuality.DataSource = tableQualityItem;
            chlFormQuality.DataBind();

            DataTable tableScienceItem = SqlHelper.ExecuteDataset(CommandType.Text, @"SELECT * FROM VIEW_KPI_SCORE_ITEM WHERE ITE_TYPE_NAME LIKE '%学科%'").Tables[0];
            chlFormScience.DataTextField = "ITEM_NAME";
            chlFormScience.DataValueField = "REC_ID";
            chlFormScience.DataSource = tableScienceItem;
            chlFormScience.DataBind();

            DataTable tableSpecialItem = SqlHelper.ExecuteDataset(CommandType.Text, @"SELECT * FROM VIEW_KPI_SCORE_ITEM WHERE ITE_TYPE_NAME LIKE '%专项%'").Tables[0];
            chlFormSpecial.DataTextField = "ITEM_NAME";
            chlFormSpecial.DataValueField = "REC_ID";
            chlFormSpecial.DataSource = tableQualityItem;
            chlFormSpecial.DataBind();

            DataTable tableManageItem = SqlHelper.ExecuteDataset(CommandType.Text, @"SELECT * FROM VIEW_KPI_SCORE_ITEM WHERE ITE_TYPE_NAME LIKE '%管理%'").Tables[0];
            chlFormManage.DataTextField = "ITEM_NAME";
            chlFormManage.DataValueField = "REC_ID";
            chlFormManage.DataSource = tableManageItem;
            chlFormManage.DataBind();



        }


        /// <summary>
        /// 加载页面列表数据
        /// </summary>
        private void BindData()
        {
            StringBuilder sqlWhere = new StringBuilder();
            String mainDataSql = @"SELECT A.REC_ID,A.TEMPLATE_NAME,A.TEMPLATE_CYCLE,A.TEMPLATE_TYPE,A.TEMPLATE_STATUS,A.TEMPLATE_REMARK,
                                    CASE WHEN A.TEMPLATE_STATUS=1 THEN '启用' WHEN A.TEMPLATE_STATUS=0 THEN '停用' END AS TEMPLATE_STATUS_NAME,
                                    (SELECT DICT_NAME FROM SYSTEM_DICT WHERE REC_ID = A.TEMPLATE_TYPE) AS TEMPLATE_TYPE_NAME,
                                    (SELECT DICT_NAME FROM SYSTEM_DICT WHERE REC_ID = A.TEMPLATE_CYCLE) AS TEMPLATE_CYCLE_NAME
                                    FROM HOS_KPI_TEMPLATE AS A WHERE 1=1 {0}";
            if (tbxNameSerach.Text.Trim() != "")
            {
                sqlWhere.Append(" AND A.TEMPLATE_NAME LIKE '%" + tbxNameSerach.Text.Trim() + "%'");
            }
            mainDataSql = string.Format(mainDataSql, sqlWhere.ToString());
            DataTable mainDataTable = SqlHelper.ExecuteDataset(CommandType.Text, mainDataSql).Tables[0];
            Grid1.DataSource = mainDataTable;
            Grid1.DataBind();
        }

        // 根据行ID来删除行数据
        private void DeleteRowByID(int rowID)
        {
            try
            {
                SqlHelper.ExecuteNonQuery(CommandType.Text, "DELETE FROM HOS_KPI_TEMPLATE WHERE REC_ID=" + rowID);
            }
            catch (Exception ex)
            {
                throw new Exception("删除失败！");
            }
        }

        protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int rowID = Convert.ToInt32(Grid1.DataKeys[e.RowIndex][0]);
                try
                {
                    DeleteRowByID(rowID);
                    BindData();
                    ShowNotify("删除数据成功!");

                }
                catch (Exception ex)
                {
                    ShowNotify("删除数据失败!");
                }
            }
        }
        protected void Grid1_PreRowDataBound(object sender, GridPreRowEventArgs e)
        {
            // 如果绑定到 DataTable，那么这里的 DataItem 就是 DataRowView
            DataRowView row = e.DataItem as DataRowView;
            int rowId = Convert.ToInt32(row["REC_ID"]);

            LinkButtonField editField = Grid1.FindColumn("Edit") as LinkButtonField;
            editField.OnClientClick = String.Format("showEditWindow('{0}');", rowId);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Dictionary<String, String> keyValuePairs = new Dictionary<string, string>();
                keyValuePairs.Clear();
                if (tbxFormTEMPLATE_NAME.Text.Trim() != "")
                {
                    keyValuePairs.Add("TEMPLATE_NAME", tbxFormTEMPLATE_NAME.Text.Trim());
                }
                else
                {
                    ShowNotify("模板名称不能为空!");
                    return;
                }
                if (tbxFormTEMPLATE_REMARK.Text.Trim() != "")
                {
                    keyValuePairs.Add("TEMPLATE_REMARK", tbxFormTEMPLATE_REMARK.Text.Trim());
                }
                if (ddlFormTEMPLATE_CYCLE.SelectedValue != "" && ddlFormTEMPLATE_CYCLE.SelectedValue != null)
                {
                    keyValuePairs.Add("TEMPLATE_CYCLE", ddlFormTEMPLATE_CYCLE.SelectedValue);
                }
                if (ddlFormTEMPLATE_TYPE.SelectedValue != "" && ddlFormTEMPLATE_TYPE.SelectedValue != null)
                {
                    keyValuePairs.Add("TEMPLATE_TYPE", ddlFormTEMPLATE_TYPE.SelectedValue);
                }
                if (ddlFormTEMPLATE_STATUS.SelectedValue != "" && ddlFormTEMPLATE_STATUS.SelectedValue != null)
                {
                    keyValuePairs.Add("TEMPLATE_STATUS", ddlFormTEMPLATE_STATUS.SelectedValue);
                }
                String strRowID = hfFormID.Text;
                if (String.IsNullOrEmpty(strRowID))
                {
                    keyValuePairs.Add("CREATE_TIME", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    keyValuePairs.Add("CREATE_USER", Session["UserID"].ToString());
                    PublicMethod.SetDataMethod("SELECT * FROM HOS_KPI_TEMPLATE WHERE 1=2", "Add", keyValuePairs);

                    ShowNotify("保存成功!");
                }
                else
                {
                    keyValuePairs.Add("REC_ID", strRowID);
                    keyValuePairs.Add("UPDATE_TIME", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    keyValuePairs.Add("UPDATE_USER", Session["UserID"].ToString());
                    PublicMethod.SetDataMethod("SELECT * FROM HOS_KPI_TEMPLATE WHERE REC_ID=" + strRowID, "Update", keyValuePairs);
                    ShowNotify("保存成功!");
                }
                // 重新绑定表格，并点击当前编辑或者新增的行
                BindData();
                PageContext.RegisterStartupScript(String.Format("F('{0}').selectRow('{1}');", Grid1.ClientID, "1") + Window1.GetHideReference());
            }
            catch (Exception ex)
            {

                throw new Exception("保存失败！");
            }

        }

        protected void btnEditDept_Click(object sender, EventArgs e)
        {
            if (Grid1.SelectedRowIndexArray.Length > 0)
            {
                Window2.GetResetReference();
                string recId = Grid1.SelectedRowID;
                DataTable dataTable = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT * FROM HOS_KPI_TEMPLATE WHERE REC_ID=" + recId).Tables[0];
                if (dataTable.Rows[0]["TEMPLATE_FOR_DEPT"].ToString() != "")
                {
                    string[] deptIDs = dataTable.Rows[0]["TEMPLATE_FOR_DEPT"].ToString().Split(',');
                    chlFormMEDICALSKILLS_LIST.SelectedValueArray = deptIDs;
                    chlFormEXECUTIVE_LIST.SelectedValueArray = deptIDs;
                    chlFormCLINI_LIST.SelectedValueArray = deptIDs;
                }
                PageContext.RegisterStartupScript(String.Format("F('{0}').show();", Window2.ClientID));
            }
            else
            {
                ShowNotify("未选中任何行!");
            }
        }

        protected void btnSaveDept_Click(object sender, EventArgs e)
        {
            Dictionary<String, String> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Clear();
            string recId = Grid1.SelectedRowID;
            StringBuilder deptIDs = new StringBuilder();
            String MedicalDeptIDs =  String.Join(",", chlFormMEDICALSKILLS_LIST.SelectedValueArray);
            String ExecutiveDeptIDs = String.Join(",", chlFormEXECUTIVE_LIST.SelectedValueArray);
            String CliniDeptIDs = String.Join(",", chlFormCLINI_LIST.SelectedValueArray);
            if (MedicalDeptIDs != "")
            {
                deptIDs.Append(MedicalDeptIDs + ",");
            }
            if (ExecutiveDeptIDs != "")
            {
                deptIDs.Append(ExecutiveDeptIDs + ",");
            }
            if (CliniDeptIDs != "")
            {
                deptIDs.Append(CliniDeptIDs + ",");
            }
            if (deptIDs.ToString() != "")
            {
                keyValuePairs.Add("REC_ID", recId);
                keyValuePairs.Add("TEMPLATE_FOR_DEPT", deptIDs.ToString().TrimEnd(','));
                keyValuePairs.Add("UPDATE_TIME", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                keyValuePairs.Add("UPDATE_USER", Session["UserID"].ToString());
                PublicMethod.SetDataMethod("SELECT * FROM HOS_KPI_TEMPLATE WHERE REC_ID=" + recId, "Update", keyValuePairs);
                ShowNotify("保存成功!");
                PageContext.RegisterStartupScript(Window2.GetHideReference());
            }
            else
            {
                ShowNotify("未选中任何科室!");
            }
        }

        protected void btnEditKPIValueItem_Click(object sender, EventArgs e)
        {
            if (Grid1.SelectedRowIndexArray.Length > 0)
            {
                Window3.GetResetReference();
                string recId = Grid1.SelectedRowID;
                DataTable dataTable = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT * FROM HOS_KPI_TEMPLATE WHERE REC_ID=" + recId).Tables[0];
                if (dataTable.Rows[0]["TEMPLATE_VALUE_ITEM"].ToString() != "")
                {
                    string[] itemIDs = dataTable.Rows[0]["TEMPLATE_VALUE_ITEM"].ToString().Split(',');
                    chlFormVALUE_ITEM.SelectedValueArray = itemIDs;
                }
                PageContext.RegisterStartupScript(String.Format("F('{0}').show();", Window3.ClientID));
            }
            else
            {
                ShowNotify("未选中任何行!");
            }
        }

        protected void btnSaveValueItem_Click(object sender, EventArgs e)
        {
            Dictionary<String, String> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Clear();
            string recId = Grid1.SelectedRowID;
            StringBuilder itemIDs = new StringBuilder();
            String valueItemIDs = String.Join(",", chlFormVALUE_ITEM.SelectedValueArray);
            if (valueItemIDs != "")
            {
                itemIDs.Append(valueItemIDs + ",");
            }
            if (itemIDs.ToString() != "")
            {
                keyValuePairs.Add("REC_ID", recId);
                keyValuePairs.Add("TEMPLATE_VALUE_ITEM", itemIDs.ToString().TrimEnd(','));
                keyValuePairs.Add("UPDATE_TIME", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                keyValuePairs.Add("UPDATE_USER", Session["UserID"].ToString());
                PublicMethod.SetDataMethod("SELECT * FROM HOS_KPI_TEMPLATE WHERE REC_ID=" + recId, "Update", keyValuePairs);
                ShowNotify("保存成功!");
                PageContext.RegisterStartupScript(Window3.GetHideReference());
            }
            else
            {
                ShowNotify("未选中任何指标!");
            }
        }

        protected void btnEditKPIScoreItem_Click(object sender, EventArgs e)
        {

            if (Grid1.SelectedRowIndexArray.Length > 0)
            {
                Window4.GetResetReference();
                string recId = Grid1.SelectedRowID;
                DataTable dataTable = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT * FROM HOS_KPI_TEMPLATE WHERE REC_ID=" + recId).Tables[0];
                if (dataTable.Rows[0]["TEMPLATE_SCORE_ITEM"].ToString() != "")
                {
                    string[] itemIDs = dataTable.Rows[0]["TEMPLATE_SCORE_ITEM"].ToString().Split(',');
                    chlFormManage.SelectedValueArray = itemIDs;
                    chlFormScience.SelectedValueArray = itemIDs;
                    chlFormQuality.SelectedValueArray = itemIDs;
                    chlFormEfficiency.SelectedValueArray = itemIDs;
                    chlFormSpecial.SelectedValueArray = itemIDs;
                }
                PageContext.RegisterStartupScript(String.Format("F('{0}').show();", Window4.ClientID));
            }
            else
            {
                ShowNotify("未选中任何行!");
            }     
        }

        protected void btnSaveScoreItem_Click(object sender, EventArgs e)
        {
            Dictionary<String, String> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Clear();
            string recId = Grid1.SelectedRowID;
            StringBuilder itemIDs = new StringBuilder();
            String manageItemIDs = String.Join(",", chlFormManage.SelectedValueArray);
            String scienceItemIDs = String.Join(",", chlFormScience.SelectedValueArray);
            String qualityItemIDs = String.Join(",", chlFormQuality.SelectedValueArray);
            String efficiencyItemIDs = String.Join(",", chlFormEfficiency.SelectedValueArray);
            String specialItemIDs = String.Join(",", chlFormSpecial.SelectedValueArray);
            if (manageItemIDs != "")
            {
                itemIDs.Append(manageItemIDs + ",");
            }
            if (scienceItemIDs != "")
            {
                itemIDs.Append(scienceItemIDs + ",");
            }
            if (qualityItemIDs != "")
            {
                itemIDs.Append(qualityItemIDs + ",");
            }
            if (efficiencyItemIDs != "")
            {
                itemIDs.Append(efficiencyItemIDs + ",");
            }
            if (specialItemIDs != "")
            {
                itemIDs.Append(specialItemIDs + ",");
            }
            if (itemIDs.ToString() != "")
            {
                keyValuePairs.Add("REC_ID", recId);
                keyValuePairs.Add("TEMPLATE_SCORE_ITEM", itemIDs.ToString().TrimEnd(','));
                keyValuePairs.Add("UPDATE_TIME", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                keyValuePairs.Add("UPDATE_USER", Session["UserID"].ToString());
                PublicMethod.SetDataMethod("SELECT * FROM HOS_KPI_TEMPLATE WHERE REC_ID=" + recId, "Update", keyValuePairs);
                ShowNotify("保存成功!");
                PageContext.RegisterStartupScript(Window4.GetHideReference());
            }
            else
            {
                ShowNotify("未选中任何指标!");
            }
           
        }

        protected void btnPreviewTemplate_Click(object sender, EventArgs e)
        {
            if (Grid1.SelectedRowIndexArray.Length > 0)
            {
                Window4.GetResetReference();
                string recId = Grid1.SelectedRowID;
                DataTable dataTable = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT * FROM HOS_KPI_TEMPLATE WHERE REC_ID=" + recId).Tables[0];
                if (dataTable.Rows[0]["TEMPLATE_SCORE_ITEM"].ToString() == "" && dataTable.Rows[0]["TEMPLATE_VALUE_ITEM"].ToString() == "")
                {
                    ShowNotify("该模板未指定任何指标项!");
                }
                else
                {
                    Window5.Title = dataTable.Rows[0]["TEMPLATE_NAME"].ToString() + "------------模板预览";
                    FineUIPro.BoundField boundFieldDept = new FineUIPro.BoundField();
                    boundFieldDept.HeaderText = "科室";
                    boundFieldDept.HeaderTextAlign = FineUIPro.TextAlign.Center;
                    boundFieldDept.DataField = "DEPT_NAME";
                    Grid2.Columns.Add(boundFieldDept);
                    if (dataTable.Rows[0]["TEMPLATE_VALUE_ITEM"].ToString() != "")
                    {
                        DataTable tableValueItems = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT REC_ID,DICT_NAME FROM SYSTEM_DICT WHERE REC_ID IN (" + dataTable.Rows[0]["TEMPLATE_VALUE_ITEM"].ToString() + ")").Tables[0];
                        foreach (DataRow dataRow  in tableValueItems.Rows)
                        {
                            FineUIPro.GroupField  groupField = new FineUIPro.GroupField();
                            groupField.HeaderText = dataRow["DICT_NAME"].ToString();
                            groupField.HeaderTextAlign = FineUIPro.TextAlign.Center;
                            FineUIPro.BoundField boundFieldTargetValue = new FineUIPro.BoundField();
                            boundFieldTargetValue.HeaderText = "目标值";
                            boundFieldTargetValue.HeaderTextAlign = FineUIPro.TextAlign.Center;
                            boundFieldTargetValue.DataField = "TARGET_VALUE";
                            FineUIPro.BoundField boundFieldRealiValue = new FineUIPro.BoundField();
                            boundFieldRealiValue.HeaderText = "实际值";
                            boundFieldRealiValue.HeaderTextAlign = FineUIPro.TextAlign.Center;
                            boundFieldRealiValue.DataField = "REALI_VALUE";
                            groupField.Columns.Add(boundFieldTargetValue);
                            groupField.Columns.Add(boundFieldRealiValue);
                            Grid2.Columns.Add(groupField);
                        }
                        
                    }
                    if (dataTable.Rows[0]["TEMPLATE_SCORE_ITEM"].ToString() != "")
                    {
                        DataTable tableItemType = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT REC_ID,DICT_NAME FROM SYSTEM_DICT WHERE REC_ID IN ( SELECT DISTINCT KPI_ITEM_TYPE FROM HOS_KPI_ITEM WHERE REC_ID IN (" + dataTable.Rows[0]["TEMPLATE_SCORE_ITEM"].ToString() + "))").Tables[0];
                        DataTable tableScoreItems = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT * FROM HOS_KPI_ITEM WHERE REC_ID IN (" + dataTable.Rows[0]["TEMPLATE_SCORE_ITEM"].ToString() + ")").Tables[0];
                        foreach (DataRow dataRow in tableItemType.Rows)
                        {
                            FineUIPro.GroupField groupField = new FineUIPro.GroupField();
                            groupField.ExpandUnusedSpace = true;
                            int allScore = 0;
                            DataRow[] dataRows = tableScoreItems.Select(" KPI_ITEM_TYPE=" + dataRow["REC_ID"].ToString());
                            foreach (DataRow row in dataRows)
                            {
                                String bindFileText = row["KPI_ITEM_NAME"].ToString() + "(" + Convert.ToInt32(row["KPI_ITEM_SCORE"].ToString()) + "分)";
                                Graphics g = Graphics.FromHwnd(IntPtr.Zero);
                                SizeF size = g.MeasureString(bindFileText, SystemFonts.DefaultFont);
                                allScore = allScore + Convert.ToInt32(row["KPI_ITEM_SCORE"].ToString());
                                FineUIPro.BoundField boundField = new FineUIPro.BoundField();
                                boundField.ExpandUnusedSpace = true;
                                boundField.MinWidth = Convert.ToInt32(size.Width);
                                boundField.HeaderText = bindFileText;
                                boundField.HeaderTextAlign = FineUIPro.TextAlign.Center;
                                boundField.DataField = "SCORE_VALUE";
                                groupField.Columns.Add(boundField);
                            }
                            groupField.HeaderText = dataRow["DICT_NAME"].ToString() + "(" + allScore + "分)";
                            groupField.HeaderTextAlign = FineUIPro.TextAlign.Center;
                            Grid2.Columns.Add(groupField);
                        }

                    }
                    if (dataTable.Rows[0]["TEMPLATE_FOR_DEPT"].ToString() != "")
                    {
                        DataTable tableDept = SqlHelper.ExecuteDataset(CommandType.Text, "SELECT DEPT_NAME FROM DEPT_DICT WHERE REC_ID IN (" + dataTable.Rows[0]["TEMPLATE_FOR_DEPT"].ToString() + ")").Tables[0];
                        Grid2.DataSource = tableDept;
                        Grid2.DataBind();
                    }
                    PageContext.RegisterStartupScript(String.Format("F('{0}').show();", Window5.ClientID));
                }
                
            }
            else
            {
                ShowNotify("未选中任何行!");
            }
        }
    }
}